home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: How big is the 0
- Date: 19 Feb 1996 12:53:30 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4g9rsa$dba@news1.usa.pipeline.com>
- NNTP-Posting-Host: pipe6.h1.usa.pipeline.com
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 17, 1996 13:24:20 in article <How big is the 0>,
- 'anh@kuhub.cc.ukans.edu' wrote:
-
- >In C, anytime I need to do a null pointer check I would do this:
- >
- > MyType *p;
- >
- > if(p==(MyType*)0)
- > bla;
- >
- >The new operator supposedly return a 0 upon failure. Can I rely on the
- >compiler to make sure the 0 is as big as the size of the pointer? For
- >example, ALPHA's pointers are 64 bits long which is different from the 32
- bits
- >int.
- >
- Yes, it's guaranteed by the language.
-
- Note that it's not necessary to cast 0 to your type, in fact, I usually
- use the shortcut version:
- if (p)
- p->DoStuff();
-
- Note 2: Global new operator returning 0 upon failure is going to
- change as the new draft standard specifies that an exception will
- be thrown instead. As of this date, no commercially available
- compiler on the PC implements this (at least not quite like the
- draft std specifies).
-
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-